package com.rd.student.jiaji.class3.xumingze.code01;

public class Test2 extends Thread {
    Object obj = new Object();

    private int start;
    private int end;

    public Test2(int start, int end)
    {
        this.start = start;
        this.end = end;
    }

    public static int num = 0;
    @Override
    public void run() {
        synchronized (obj) {
            try {
                for(int i = start;i < end;i++)
                {
                    num += i;
                    System.out.println(getName() + " " + i );
                }
                System.out.println(num);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }


    public static void main(String[] args) throws InterruptedException {
        Test2 t1 = new Test2(1,11);
        Test2 t2 = new Test2(11,21);
        Test2 t3 = new Test2(21,31);
        Test2 t4 = new Test2(31,41);
        Test2 t5 = new Test2(41,51);
        Test2 t6 = new Test2(51,61);
        Test2 t7 = new Test2(61,71);
        Test2 t8 = new Test2(71,81);
        Test2 t9 = new Test2(81,91);
        Test2 t10 = new Test2(91,101);
//        Thread t1 = new Thread(test2);
//        Thread t2 = new Thread(test2);
//        Thread t3 = new Thread(test2);
//        Thread t4 = new Thread(test2);
//        Thread t5 = new Thread(test2);
//        Thread t6 = new Thread(test2);
//        Thread t7 = new Thread(test2);
//        Thread t8 = new Thread(test2);
//        Thread t9 = new Thread(test2);
//        Thread t10 = new Thread(test2);

        t1.start();
        t1.join();
        t2.start();
        t2.join();
        t3.start();
        t3.join();
        t4.start();
        t4.join();
        t5.start();
        t5.join();
        t6.start();
        t6.join();
        t7.start();
        t7.join();
        t8.start();
        t8.join();
        t9.start();
        t9.join();
        t10.start();
    }
}
